<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>医生列表</title>
<c:if test="${fn:contains(sessionInfo.resourceList, '/reserveRegister/add')}">
	<script type="text/javascript">
		$.canAdd = true;
	</script>
</c:if>
<script type="text/javascript">
	var dataGrid;
	var departmentTree;
	
	$(function() {
		departmentTree = $('#departmentTree').tree({
			url : '${ctx}/department/listName',
			lines : true,
			onClick : function(node) {
				dataGrid.datagrid('load', {
					departmentId : node.id
				});
			}
		});
		dataGrid = $('#dataGrid').datagrid({
			url : '${ctx}' + '/reserveRegister/doctorDataGrid',
			striped : true,
			rownumbers : true,
			pagination : true,
			singleSelect : true,
			idField : 'doctorId',
			sortName : 'id',
			sortOrder : 'asc',
			pageSize : 50,
			pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,
					400, 500 ],
			frozenColumns : [ [ {
				width: '50',
				title: '编号',
				field: 'id',
				sortable: true
			} ]],
			columns :[[{
				width : '100',
				title : '医生姓名',
				field : 'name',
				sortable : true
			}, {
				width : '80',
				title : '科室ID',
				field : 'departmentId',
				hidden : true
			}, {
				width : '80',
				title : '所属科室',
				field : 'departmentName'
			},{
				field : 'action',
				title : '操作',
				width : 100,
				formatter : function(value, row, index) {
					var str = '&nbsp;';
					if($.canAdd) {
						str += $.formatString('<a href="javascript:void(0)" onclick="addFun(\'{0}\',\'{1}\');" >挂号</a>',row.id,row.name);
					}
					str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
					str += $.formatString('<a href="javascript:void(0)" onclick="introduction(\'{0}\',\'{1}\');" >介绍</a>', row.id,row.name);
					return str;
				}
			}] ],
		});
	});

	function addFun(doctorId,doctorName) {
		if (doctorId == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			doctorId = rows[0].doctorId;
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		debugger;
		parent.$.modalDialog({
			title : doctorName + '医生',
			width : 900,
			height : 400,
			href : '${ctx}/reserveRegister/addPage?doctorId=' + doctorId,
		});
	}
	function introduction(doctorId,doctorName) {
		if (doctorId == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			doctorId = rows[0].doctorId;
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.modalDialog({
			title : doctorName + '医生',
			width : 600,
			height : 500,
			href : '${ctx}/reserveRegister/introductionPage?doctorId=' + doctorId,
		});
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',fit:true,border:false" title="医生列表">
		<table id="dataGrid" data-options="fit:true,border:false"></table>
	</div>
	<div data-options="region:'west',border:false,split:true" title="科室"
		style="width: 160px; overflow: hidden;">
		<table id="departmentTree"
			style="width: 120px; margin: 10px 10px 10px 10px"></table>
	</div>

</body>
</html>